import time
from selenium.webdriver.common.by import By
from common.base import Base
from common.functions import open_browser


class GenerateOrdersPage(Base):
    generate_orders_url = 'http://139.129.26.163/flow.php?step=checkout'

    # 修改1
    def revise1(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[1]/h6/a[@class="f6"]'))

    # 修改2
    def revise2(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[3]/h6/a[@class="f6"]'))

    # 配送方式为申通快递
    def delivery_method1(self):
        self.click((By.XPATH, '//table[@id="shippingTable"]/tbody/tr[2]/td/input[@value="5"]'))

    # 配送方式为邮局
    def delivery_method2(self):
        self.click((By.XPATH, '//input[@value="6"]'))

    # 配送是否需要保价
    def insured(self):
        self.click((By.ID, 'ECS_NEEDINSURE'))

    # 支付方式为余额支付
    def pay1(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[7]/table/tbody/tr[2]/td/input[@value="1"]'))

    # 支付方式为银行支付
    def pay2(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[7]/table/tbody/tr[3]/td/input[@value="2"]'))

    # 支付方式为货到付款
    def pay3(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[9]/table/tbody/tr[2]/td/input[@value="0"]'))

    # 商品包装为不要包装
    def package1(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[9]/table/tbody/tr[2]/td/input[@value="0"]'))

    # 商品包装为精品包装
    def package2(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[9]/table/tbody/tr[3]/td/input[@value="1"]'))

    # 查看1
    def check1(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[9]/table/tbody/tr[3]/td[5]/a'))

    # 不要贺卡
    def card1(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[11]/table/tbody/tr[2]/td/input'))

    # 祝福贺卡
    def card2(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[11]/table/tbody/tr[3]/td/input'))

    # 查看2
    def check2(self):
        self.click((By.XPATH, '//div[@class="block"]/form/div[11]/table/tbody/tr[3]/td[5]/a'))

    # 祝福语
    def greetings(self, content):
        self.send_keys((By.XPATH, '//div[@class="block"]/form/div[11]/table/tbody/tr[4]/td[3]/textarea'), content)

    # 选择红包
    def envelope1(self, index):
        self.select_by_index((By.ID, 'ECS_BONUS'), index)

    # 红包序列号
    def envelope2(self, content):
        self.send_keys((By.NAME, 'bonus_sn'), content)

    # 验证红包
    def envelope3(self):
        self.click((By.NAME, 'validate_bonus'))

    # 发票
    def bill1(self):
        self.click((By.NAME, 'need_inv'))

    def bill2(self, index):
        self.select_by_index((By.NAME, 'inv_type'), index)

    def bill3(self, content):
        self.send_keys((By.NAME, 'inv_payee'), content)

    def bill4(self, index):
        self.select_by_index((By.NAME, 'inv_content'), index)

    # 订单附言
    def postscript(self, content):
        self.send_keys((By.NAME, 'postscript'), content)

    # 缺货处理
    def stock1(self):
        self.click((By.XPATH, '//input[@name="how_oos" and @value="0"]'))

    def stock2(self):
        self.click((By.XPATH, '//input[@name="how_oos" and @value="1"]'))

    def stock3(self):
        self.click((By.XPATH, '//input[@name="how_oos" and @value="2"]'))

    # 提交订单
    def submit(self):
        self.click((By.XPATH, '//input[@type="image"]'))


if __name__ == '__main__':
    browser = open_browser()
    case = GenerateOrdersPage(browser)
